library(tidyverse)

# Read and clean data
df <- read_csv("pjp-number-participants.csv") %>%
  select(WEEK, `TOTAL RESPONSES`) %>%
  rename(
    week = WEEK,
    totalResponses = `TOTAL RESPONSES`
  ) %>%
  # Convert week to numeric, removing any non-numeric characters
  mutate(week = as.numeric(gsub("[^0-9]", "", week))) %>%
  # Remove any NA rows
  filter(!is.na(week), !is.na(totalResponses))

# Create the line plot
lineplot_participation <- ggplot(df, aes(x = week, y = totalResponses)) +
  geom_line(color = "#4DBBD5", size = 1) +
  geom_point(color = "#4DBBD5", size = 2) +
  scale_x_continuous(
    breaks = seq(0, max(df$week), by = 10)  # Show every 10th week
  ) +
  scale_y_continuous(
    labels = scales::comma,  # Add commas to y-axis labels
    breaks = seq(0, max(df$totalResponses), by = 200)
  ) +
  labs(
    title = "Number of Participants by Week",
    x = "Week",
    y = "Number of Responses"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    panel.grid.minor = element_blank(),
    plot.title = element_text(hjust = 0.5)
  )


barplot_participation<- ggplot(df, aes(x = week, y = totalResponses)) +
  geom_bar(stat = "identity", fill = "#4DBBD5", width = 0.7) +
  scale_x_continuous(
    breaks = seq(0, max(df$week), by = 10)
  ) +
  scale_y_continuous(
    labels = scales::comma,
    breaks = seq(0, max(df$totalResponses), by = 200)
  ) +
  labs(
    title = "Number of Participants by Week",
    x = "Week",
    y = "Number of Responses"
  ) + 
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    panel.grid.minor = element_blank(),
    plot.title = element_text(hjust = 0.5)
  )

# Save the plots
# ggsave("panel_participation_line.png", lineplot_participation, width = 12, height = 8, dpi = 300)
# This generates figure 7
ggsave("panel_participation_bar.png", barplot_participation, width = 12, height = 8, dpi = 300)